<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间序列预测结果</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
        body {
            font-family: 'Roboto', Arial, sans-serif;
            margin: 20px;
            padding: 20px;
            background: url('static/nightcity.jpg') no-repeat center center fixed;
            background-size: cover;
            color: #333;
        }
        .content {
            background-color: rgba(255, 255, 255, 0.8);
            padding: 20px;
            border-radius: 10px;
        }
        .output-section {
            background-color: #f9f9f9;
            border: 1px solid #ccc;
            padding: 20px;
            margin-bottom: 20px;
        }
        .error-message {
            color: red;
            font-weight: bold;
        }
        .prediction-result {
            font-size: 24px;
            font-family: 'Roboto', Arial, sans-serif;
        }
        pre {
            font-family: 'Roboto', Arial, sans-serif;
        }
        .scatter-plot {
            margin-top: 20px;
        }
    </style>
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
    <div class="content">
        <h1>时间序列预测执行结果</h1>

        <div class="output-section">
            <h3 class="prediction-result">The Prediction Result:</h3>
            <pre>{{ output | safe }}</pre>
        </div>

        {% if error %}
        <div class="output-section">
            <p class="error-message">Error: {{ error }}</p>
        </div>
        {% endif %}



        <div class="output-section scatter-plot">
            <!-- 绘制原始数据折线图 -->
            <h3>原始数据图表</h3>
            <div id="originalDataPlot" style="width: 80%; height: 400px;"></div>
        </div>

        <div class="output-section scatter-plot">
            <!-- 使用提取的预测结果数据绘制散点图 -->
            <h3>预测结果散点图</h3>
            <div id="scatterPlot" style="width: 80%; height: 400px;"></div>
        </div>
    </div>

    <script>
        // 使用提取的预测结果数据绘制散点图
        var predictionResults = {{ prediction_results | safe }};
        var periods = Array.from(Array(predictionResults.length).keys());

        var scatterData = [{
            x: periods,
            y: predictionResults,
            mode: 'lines',
            type: 'scatter'
        }];

        var scatterLayout = {
            title: 'Prediction Results Scatter Plot',
            xaxis: {
                title: 'Timestamp'
            },
            yaxis: {
                title: 'Prediction Value'
            }
        };

        Plotly.newPlot('scatterPlot', scatterData, scatterLayout);

        // 绘制原始数据折线图
        var originalData = {{ original_data | safe }};
        // var firstTenData = originalData.slice(0, 10); // 截取前 10 个数据点
        //var timestamps = firstTenData.map(item => item.timestamp); // 提取时间戳
        var periods_data = Array.from(Array(originalData.length).keys());
        //var values = firstTenData.map(item => item.value); // 提取值


        var lineData = [{
            x: periods_data,
            y: originalData,
            mode: 'lines',
            type: 'scatter'
        }];

        var lineLayout = {
            title: 'Original Data Line Plot',
            xaxis: {
                title: 'Timestamp'
            },
            yaxis: {
                title: 'Value'
            }
        };

        Plotly.newPlot('originalDataPlot', lineData, lineLayout);
    </script>
</body>
</html>
